﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SoundManager : MonoBehaviour 
{

    public static SoundManager instance;
    public AudioSource soundEffectAudioSource;
    public AudioSource soundBGAudioSource;
    void Awake()
    {
        instance = this;
    }


    /// <summary>
    /// 根据名字播放音效
    /// </summary>
    /// <param name="name"></param>
    public void Play(string name)
    {
        Debug.Log("播放声音:"+name);
        soundEffectAudioSource.clip = Resources.Load("Sound/"+name) as AudioClip;
        soundEffectAudioSource.Play();
       
    }

    /// <summary>
    /// 播放普通音效
    /// </summary>
    /// <param name="audioClip"></param>
    public void PlaySoundEffect(AudioClip audioClip)
    {
        soundEffectAudioSource.clip = audioClip;
        soundEffectAudioSource.Play();

    }


    /// <summary>
    /// 循环播放普通音效
    /// </summary>
    /// <param name="audioClip"></param>
    public void PlaySoundEffect(AudioClip audioClip,bool isLoop)
    {
        soundEffectAudioSource.clip = audioClip;
        soundEffectAudioSource.loop = isLoop;
        soundEffectAudioSource.Play();

    }

    /// <summary>
    /// 停止播放音效
    /// </summary>
    public void StopSoundEffect(AudioClip audioClip)
    {
        Debug.Log("StopAlarm");
        soundEffectAudioSource.clip = audioClip;
        soundBGAudioSource.Pause();
    }


    /// <summary>
    /// 播放背景音乐
    /// </summary>
    /// <param name="audioClip"></param>
    public void PlayBGMusic(AudioClip audioClip)
    {
        soundBGAudioSource.clip = audioClip;
        soundBGAudioSource.Play();
    }

}
